<?php

class Core_Model_Media_Ebook extends Dcmp_Model_Tag {

    public function __construct() {
        parent::__construct();
        $this->tagType = 'ebook';
    }

    public function updateLimitTimes(){
        Kd_Data_Factory::getUpdateDcl()
                ->into($this->getTable()->getName())
                ->value('limit_times', Kd_Data_Dcl_Fn::subtract('limit_times', 1))
                ->where()->eq('id', ':id:i')->closest()
                ->addParameter('id', $this->getId())
                ->execute();
        return $this;
    }

    protected function initializeTable($table) {
        $table->setName('{t}media_ebook');
        $table->createColumn('id', 'integer', TRUE, TRUE);
        $table->createColumn('title', 'string');
        $table->createColumn('sd_url', 'string');
        $table->createColumn('hd_url', 'string');
        $table->createColumn('status', 'string');
        $table->createColumn('limit_times', 'integer');
        $table->createColumn('access_password', 'string');
        $table->createColumn('access_limit', 'integer')->setDefaultValue('0');
        parent::initializeTable($table);
    }

}